import sys
sys.path.append("..")

import utils.raster as raster
import os
import datetime
import pandas as pd
import utils.text as text
import math
# for root,folder,files in os.walk("/mnt/fire/Extract/fi"):
# 	for file in files:
# 		if file.endswith(".tif"):
# 			info,data = raster.open(os.path.join(root,file))

# 			print(info[1])
# 			print(data.shape)

corrdinate = pd.read_csv("/mnt/fire/station/randomp/point.csv")

result = []

for year in range(2007,2017):
	for doy in range(1,366,8):
		tmp = "%d%03d"%(year,doy)

		if year == 2007 and doy in [1,9]:
			continue

		if year == 2010 and doy in [321,329]:
			tmp = "%s\t%s"%(tmp,"\t".join([ "%s"%(-1) for x in range(len(corrdinate))]))
			result.append(tmp + "\n")
			continue

		info,data = raster.open(os.path.join("/mnt/fire/Extract/fi","%d_%d.tif"%(year,doy)))

		for i in range(0,len(corrdinate)):
			xy = [math.floor(x) for x in raster.latlont2imgXY([corrdinate["lon"][i],corrdinate["lat"][i]],info[1])]

			tmp = "%s\t%f"%(tmp,data[xy[1]][xy[0]])

		result.append(tmp + "\n")

text.save("/mnt/fire/fi.txt",result)




		
